
words_list = []
words_dict = []


def load_words():
    global words_list, words_dict

    with open('words.txt', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            word = line.strip()
            words_list.append(word)
    print('words_list', len(words_list))

    with open('dic.txt', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            item = line.strip().split(u'\uf8f5')
            words_dict.append(item[:3])
    print('words_dict', len(words_dict))
    print()


def query_words(query_str):
    print(query_str)
    print()

    query_list = query_str.strip().lower().split()
    if len(query_list) == 0:
        return
    
    for word in words_list:
        if all(query in word.lower() for query in query_list):
            print(word)
    print()
            
    for item in words_dict:
        if all(query in item[0].lower() for query in query_list):
            print(item)
    print()


if __name__ == '__main__':  
    load_words()
    query_words('b an na r t  l e ')